package com.zr.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zr.model.User;
import com.zr.service.UserService;

import net.sf.json.JSONObject;
/**
 * 用户信息修改的servlet
 * @author Administrator
 *
 */
public class UpdateUserController extends HttpServlet{
	//实例化对应的服务层
	  UserService userservice = new UserService();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	// TODO Auto-generated method stub
	doPost(req, resp);
}
@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
	req.setCharacterEncoding("utf8");
	//接受页面传过来的值
	String user = req.getParameter("user");
	//将取到的字符串转换成json对象
	JSONObject json = JSONObject.fromObject(user);   
	//将json对象转换为java对象
	User newUser = (User) JSONObject.toBean(json, User.class);
	boolean flag = userservice.updateUser(newUser);	
	//拿到这只笔
	PrintWriter pw = resp.getWriter();
	pw.write(flag+"");
	}
}
